import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ShopOperType } from "../../shop/ShopOperType";
import { CursorManager } from "../../../manager/CursorManager";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { PetEquipItemRenderer } from "./PetEquipItemRenderer";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ItemData } from "../../../resource/info/ItemData";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetEquipsBagWin
    
    export  class PetEquipsBagWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(240, 445);
            this.titleHeight = 25;
            this.title = Language.getString(61302);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.shop.operType;
            switch (loc1) 
            {
                case ShopOperType.SALE:
                {
                    CursorManager.showCursor(CursorManager.SELL);
                    break;
                }
                case ShopOperType.FIX:
                {
                    CursorManager.showCursor(CursorManager.FIX);
                    break;
                }
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.showCursor(CursorManager.NO_CURSOR);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            super.createChildren();
            ObjCreate.createBg(18, 36, 204, 316, this);
            var loc2=0;
            while (loc2 < 35) 
            {
                loc1 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc1.x = loc2 % 5 * 40 + 20;
                loc1.y = Math.floor(loc2 / 5) * 40 + 40;
                this.addChild(loc1);
                ++loc2;
            }
            this._equipsTile = ObjCreate.createTileList(20, 40, 205, 285, this);
            this._equipsTile.columnWidth = 40;
            this._equipsTile.rowHeight = 40;
            this._equipsTile.setStyle("cellRenderer", PetEquipItemRenderer);
            this._pageSec = ObjCreate.createPageSelecter(80, 327, this);
            this._pageSec.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            ObjCreate.createLabel(Language.getString(61303), 0, 358, 240, 20, flash.text.TextFormatAlign.CENTER, this, true, GlobalStyle.color5Uint);
            this._saleBtn = ObjCreate.createGButton(Language.getString(61304), 45, 383, 70, 22, this);
            this._repairBtn = ObjCreate.createGButton(Language.getString(61306), 130, 383, 70, 22, this);
            this._allRepairBtn = ObjCreate.createGButton(Language.getString(61307), 130, 410, 70, 22, this);
            this._allRepairBtn.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onGetAllRepairTooltip);
            this._forgeBtn = ObjCreate.createGButton(Language.getString(61305), 45, 410, 70, 22, this);
            this._saleBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._repairBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._allRepairBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._forgeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            return;
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this.updateEquips();
            return;
        }

        public updateEquips(): void
        {
            var loc1=Cache.instance.pack.backPackCache.getItemsByJudge(this.isPetEquips);
            this._pageSec.maxPage = Math.ceil(loc1.length / this._pagesize);
            var loc2=(this._pageSec.currentPage - 1) * this._pagesize;
            var loc3=this._pageSec.currentPage * this._pagesize > loc1.length ? loc1.length : this._pageSec.currentPage * this._pagesize;
            var loc4=loc1.slice(loc2, loc3);
            this._equipsTile.dataProvider = new DataProvider(loc4);
            return;
        }

        /* internal  */isPetEquips(arg1: ItemData): Boolean
        {
            return arg1.category == ECategory._ECategoryPetEquip;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._saleBtn:
                {
                    if (Cache.instance.shop.operType != ShopOperType.SALE) 
                    {
                        Cache.instance.shop.operType = ShopOperType.SALE;
                    }
                    else 
                    {
                        Cache.instance.shop.operType = "";
                    }
                    break;
                }
                case this._repairBtn:
                {
                    if (Cache.instance.shop.operType != ShopOperType.FIX) 
                    {
                        Cache.instance.shop.operType = ShopOperType.FIX;
                    }
                    else 
                    {
                        Cache.instance.shop.operType = "";
                    }
                    break;
                }
                case this._allRepairBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipRepairAll));
                    break;
                }
                case this._forgeBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipForge_ShowForgeModule));
                    break;
                }
            }
            return;
        }

        /* internal  */onGetAllRepairTooltip(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._allRepairBtn.toolTipData = HTMLUtil.addColor(Language.getStringByParam(61337, "0"), "#FFFFFF");
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipGetAllRepairCost));
            Dispatcher.addEventListener(EventName.PetEquipGetAllRepairCostSuccess, this.onGetAllRepairCostSuccess);
            return;
        }

        /* internal  */onGetAllRepairCostSuccess(arg1: DataEvent): void
        {
            Dispatcher.removeEventListener(EventName.PetEquipGetAllRepairCostSuccess, this.onGetAllRepairCostSuccess);
            this._allRepairBtn.toolTipData = HTMLUtil.addColor(Language.getStringByParam(61337, arg1.data), "#FFFFFF");
            return;
        }

        public /* override */ hide(): void
        {
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (Cache.instance.shop.operType == ShopOperType.SALE) 
            {
                Cache.instance.shop.operType = "";
            }
            return;
        }

        protected /* override */ onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        public /* override */ setTop(arg1: Object /* flash.display.DisplayObject */): void
        {
            return;
        }

        /* internal */ /* var */_pagesize: int=35;

        /* internal */ /* var */_equipsTile: GTileList;

        /* internal */ /* var */_pageSec: PageSelecter;

        /* internal */ /* var */_saleBtn: GButton;

        /* internal */ /* var */_repairBtn: GButton;

        /* internal */ /* var */_allRepairBtn: GButton;

        /* internal */ /* var */_forgeBtn: GButton;
    }
